Configure
Module for configuring and providing http clients
Simple
const configure = (config) => {
config.http.configureClient(
'bar',
'https://somewhere-test.com'
);
}
Standard
const configure = (config) => {
config.http.configureClient(
'bar',
{
baseUri: 'https://foo.bar',
defaultScopes: ['foobar/.default']
}
);
}
Callback
const configure = async(config) => {
config.http.configureClient(
'bar',
(client): => {
client.uri = 'https://foo.bar'
client.defaultScopes: ['foobar/.default']
}
);
}
Consumption
const client = modules.http.createClient('foo');
const selector = (response: Response): Promise<FooBar> => response.json();
client.fetch('/api/admin', {selector, scopes: ['foobar/.admin']}).subscribe(x => console.log(x));
client.fetchAsync('/api', {selector}).then(console.log);
Operators
const client = modules.http.createClient('foo');
const logger = console.debug;
client.requestHandler.add((x: Request) => logger(x));
client.responseHandler.add((x: Request) => logger(x));